package org.testis.webautomationmodule.ui.objects;

import org.testis.logging.AtofLogLevel;
import org.testis.webautomationmodule.ui.UIFormFieldDecorator;


public class UITextBox extends UIFormFieldDecorator
{

    public UITextBox(String id)
    {
        super(id);
    }


    public UITextBox(String id,
                     String value)
    {
        super(id,
              value);

    }


    @Override
    protected boolean setBehavior()
    {
        if (checkAvailableForAction()) {
            getWebAutomationImpl().type(getId(),
                                        getValue());
            putLog(" typing " + getValue() + " to the textbox with id " +
                   getId());
            return true;
        }
        return true;
    }


    @Override
    public boolean verifyBehavior()
    {
        String getInputType = getWebAutomationImpl().getEval(
            "function atof_getInputType(){var inputObj=selenium.browserbot.getDocument().getElementById('" +
            getId() + "'); " +
            " var type=inputObj.getAttribute('type');" +
            "return type}; eval('atof_getInputType()');");
        if (getInputType != null) {
            if (getInputType.toLowerCase().equals(
                "password")) {
                putLog(
                    " textbox with type of password  with id " +
                    getId() +
                    " can not verified...Due to password field constraint...  ",
                    AtofLogLevel.WARN);
                return true;
            }
        }

        return super.verifyBehavior();
    }
}

